﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web.Mvc;
using Api.Common;

namespace Api.Model
{
    [Table("methodparameter")]
    public class MethodParameter : BaseUserModel
    {
        public int MethodId { get; set; }
        public ParameterType Type { get; set; }
        [MaxLength(100)]
        public string Name { get; set; }
        [MaxLength(50)]
        public string DataType { get; set; }
        /// <summary>
        /// 是否必須
        /// </summary>
        public bool IsRequired { get; set; }
        /// <summary>
        /// 默認值
        /// </summary>
        [MaxLength(50)]
        public string DefaultValue { get; set; }
        [Column(TypeName = "text")]
        public string Description { get; set; }
        public int ProjectId { get; set; }
        [NotMapped]
        public string DescriptionIgnorHtml
        {
            get
            {
                var description = Description ?? "";
                var result = Regex.Replace(description, "<[^>]*>", "").NoHTML().Replace(" ", "").Replace("\n", "").Replace("\t", "").Replace("\r", "");
                StringBuilder sb = new StringBuilder();
                var length = result.Length;

                int count = 80;
                for (int i = 0; i <= length / count; i++)
                {
                    if (result.Length > i * count + count)
                    {
                        sb.Append(result.Substring(i * count, count));
                    }
                    else
                    {
                        sb.Append(result.Substring(i * count));
                    }
                    if (length / count > 0 && i != length / count)
                        sb.Append(Environment.NewLine + "///");
                }
                return sb.ToString();
            }
        }
    }
}
